<template>
  <div>
    <bbw-table
            :tableData.sync="tableData"
            @onFinish="onFinish"
            :header="header"
    >

    </bbw-table>
  </div>
</template>

<script>
    import api from '../utils/api'
    import {get, post} from '../utils/request'
    export default {
        data(){
            return {
                tableData:[],
                column:[

                ],
                header:[
                    {
                        label: '编号',
                        value:'id',
                        type: 'text'
                    },
                    {
                        label: '载重',
                        value: 'loads'
                    },
                    {
                        label: '船龄',
                        value:'old'
                    },
                    {
                        label: '日期',
                        value:'publish_time',
                        type:'text'
                    },
                    //
                    // {
                    //     label: '发布',
                    //     value:'status',
                    //     type:'switch'
                    // },
                    // {
                    //     label: '创建日期',
                    //     value:'create_time',
                    //     type:'text'
                    // },
                    // {
                    //     label: '发布日期',
                    //     value:'publish_time',
                    //     type:'text'
                    // }

                ],
                type: 0
            }
        },
        props: {
            // msg: String
        },
        watch:{
            ['$route.query.type']:{
                handler(val){
                    this.tableData = []
                    let type = val
                    this.type = type
                    console.log(type)
                    this.getData(type)
                },
                immediate: true

            }
        },
        mounted(){
            // let type = this.$route.query.type
            // this.type = type
            // // console.log(this.$route.query.type)
            // this.getData(type)
        },
        methods:{
            getData(type){
                get(api.getTransaction,{type,status : type}).then(res=>{
                    this.tableData = res.data
                }).catch(err=>{

                })
            },
            onFinish(data){
                post(api.addTransaction,{
                    data,
                    type:this.type,
                    status : this.type
                }).then(res=>{
                    this.$message(res.msg)
                    this.getData(this.type)
                }).catch(err=>{
                    this.getData(this.type)
                    this.$message(err.msg||'提交错误')
                })
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
